const express = require('express')

const app = express()
const hostname = '127.0.0.1'
const port = 3000

// const NacosNamingClient = require('nacos').NacosNamingClient
// const instanceName='nodejs-service'

// const nacosClient = new NacosNamingClient({
//     logger: console,
//     serverList:'127.0.0.1:8848',
//     namespace:'public'
// })

// nacosClient.ready().then(()=>{
//    nacosClient.registerInstance(instanceName,{
//     ip:hostname,
//     port:port
//    })
// })

const data = [
    {
        name:'张三',
        age:15,
        sex:'男'
    },
    {
        name:'李四',
        age:25,
        sex:'男'
    },
    {
        name:'王五',
        age:33,
        sex:'女'
    }
]

app.use((req,res,next) => {
    console.log(`收到请求${req.url}`);
    console.log(`请求来自于${req.get('Host')}`);
    next()
})

app.get('/student',(req,res)=>{
    res.setHeader('Content-Type', 'application/json;charset=utf-8')
     res.send(JSON.stringify(data))
})


app.listen(port,hostname,()=>{
    console.log("服务已启动，访问student数据："+"http://"+hostname+":"+port+"/student");
})
